using System;
using Provausio.Common.Objects;
using TrainingManagement.api.Models.Data.CRUD;
using TrainingManagement.api.Models.Data.CRUD.DepartmentTree;

namespace TrainingManagement.api.Models.BusinessLogic.DepartmentTree
{
    public class DepartmentTreeCreateOperation : BusinessOperation<BusinessObjects.DepartmentTree, BusinessObjects.DepartmentTree>
    {
        readonly DepartmentTreeInsertDataSource _departmentTreeInsert = new DepartmentTreeInsertDataSource();

        public override BusinessObjects.DepartmentTree Run(BusinessObjects.DepartmentTree input)
        {
            if (_departmentTreeInsert.Execute(input))
                return input;
            throw new Exception(string.Format("{0}>{1} failed to save!", input.ParentTitle, input.ChildTitle));
        }
    }
}